//
//  GroupCollectionViewCell.m
//  YMIM
//
//  Created by admin on 2022/3/25.
//

#import "GroupCollectionViewCell.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
#import <MJExtension/MJExtension.h>
@implementation GroupCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
     
        [self initView];
    }
    
    return self;
}
-(void)setUserInfo:(YMUserInfo *)userInfo{
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:userInfo.userAvatar]];
    self.nameLable.text = userInfo.userName;
}
-(void)initView{
    
    [self.contentView addSubview:self.headImageView];
    [self.contentView addSubview:self.nameLable];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.centerX.mas_lessThanOrEqualTo(self.contentView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(45, 45));
    }];
    [self.nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.headImageView.mas_bottom).offset(4);
        make.centerX.mas_equalTo(self.headImageView.mas_centerX);
        make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/5);
        
    }];
    
    [self.contentView addSubview:self.deleteButton];
    [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.mas_equalTo(self.contentView.mas_centerX);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
    }];
    
    [self.contentView addSubview:self.addButton];
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.mas_equalTo(self.contentView.mas_centerX);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
    }];
}
-(UIButton *)deleteButton{
    
    if (_deleteButton == nil) {
        
        _deleteButton = [[UIButton alloc]init];
        [_deleteButton setImage:[UIImage imageNamed:@"Delete_Member"] forState:UIControlStateNormal];
        [_deleteButton setTitle:@"移除" forState:UIControlStateNormal];
        [_deleteButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _deleteButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _deleteButton.titleEdgeInsets = UIEdgeInsetsMake(70,-45,0,0);
        _deleteButton.imageEdgeInsets = UIEdgeInsetsMake(0,10,0,0);
    }
    
    return _deleteButton;
}

-(UIButton *)addButton{
    
    if (_addButton == nil) {
        
        _addButton = [[UIButton alloc]init];
        [_addButton setImage:[UIImage imageNamed:@"Add_Member"] forState:UIControlStateNormal];
        [_addButton setTitle:@"邀请" forState:UIControlStateNormal];
        [_addButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _addButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _addButton.titleEdgeInsets = UIEdgeInsetsMake(70,-45,0,0);
        _addButton.imageEdgeInsets = UIEdgeInsetsMake(0,10,0,0);
    }
    
    return _addButton;
}

-(UILabel *)nameLable{
    
    if (_nameLable == nil) {
        
        _nameLable = [[UILabel alloc]init];
        _nameLable.font = [UIFont systemFontOfSize:14];
        _nameLable.textColor = [UIColor blackColor];
        _nameLable.textAlignment = NSTextAlignmentCenter;
    }
    
    return _nameLable;
}
-(UIImageView *)headImageView{
    
    if (_headImageView == nil) {
        
        _headImageView = [[UIImageView alloc]init];
        _headImageView.backgroundColor = [UIColor clearColor];
        _headImageView.layer.cornerRadius = 22.5;
        _headImageView.clipsToBounds = YES;
    }
    
    return _headImageView;
}

@end
